﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MotoCommon
{
    public class MotoCommon
    {
        public static string GetDevid()
        {
            string uuid = "";
            Symbol.ResourceCoordination.TerminalInfo terminalInfo = new Symbol.ResourceCoordination.TerminalInfo();
            foreach (byte b in terminalInfo.UniqueUnitID)
                uuid += b.ToString("X2");
            return uuid;
        }

        public static List<string> splitStr(string mString, char str)
        {
            try
            {
                List<string> al = new List<string>();
                if (mString != "")
                {
                    string[] arr = mString.Split(str);

                    for (int i = 0; i < arr.Length; i++)
                    {
                        if (arr[i].Trim() != "")
                        {
                            al.Add(arr[i]);
                        }
                    }
                }
                return al;
            }
            catch (Exception err)
            {
                string e = err.Message;
                return null;
            }
        }

        public static string str2print(string str, int index)
        {
            int len = trueLength(str);
            string space1 = "            ";
            string space2 = "     ";
            string space3 = "        ";
            switch (index)
            {
                case 1:
                    if (len < 12)
                    {
                        str += space1.Substring(0, space1.Length - len);
                    }
                    break;
                case 2:
                    if (len < 5)
                    {
                        str += space2.Substring(0, space2.Length - len);
                    }
                    break;
                default:
                    if (len < 8)
                    {
                        str += space3.Substring(0, space3.Length - len);
                    }
                    break;
            }

            return str;
        }

        private static int trueLength(string str)
        {

            // str 字符串
            // return 字符串的字节长度
            int lenTotal = 0;
            int n = str.Length;
            string strWord = "";
            int asc;
            for (int i = 0; i < n; i++)
            {
                strWord = str.Substring(i, 1);
                asc = Convert.ToChar(strWord);
                if (asc < 0 || asc > 127)
                    lenTotal = lenTotal + 2;
                else
                    lenTotal = lenTotal + 1;
            }

            return lenTotal;
        }
    }
}
